<?php
declare(strict_types=1);

namespace app\model;

use think\Model;

class MessageRecord extends Model
{
    protected $table = 'message_record';
    
    // 关联用户
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    
    // 关联模板
    public function template()
    {
        return $this->belongsTo(MessageTemplateConfig::class, 'template_id', 'template_id');
    }
    
    // 消息类型获取器
    public function getMessageTypeTextAttr($value, $data)
    {
        $types = [
            1 => '公众号消息',
            2 => '小程序消息',
            3 => '短信'
        ];
        return $types[$data['message_type']] ?? '未知';
    }
    
    // 状态获取器
    public function getStatusTextAttr($value, $data)
    {
        $status = [
            0 => '待发送',
            1 => '发送成功',
            2 => '发送失败'
        ];
        return $status[$data['status']] ?? '未知';
    }
}